package com.chen.authority.common.response;

import cn.hutool.http.HttpStatus;
import com.chen.authority.common.constant.SysConstant;

/**
 * 基础响应
 *
 * @author chengy
 * @date 2022/9/27
 */
public class Response {

    /**
     * 响应状态码
     */
    private int code;

    /**
     * 响应消息
     */
    private String message;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    /**
     * 成功响应
     *
     * @return 响应
     */
    public static Response success() {
        Response response = new Response();
        response.setCode(HttpStatus.HTTP_OK);
        response.setMessage(SysConstant.SUCCESS_MSG);
        return response;
    }

    /**
     * 失败响应
     *
     * @return 响应
     */
    public static Response fail() {
        Response response = new Response();
        response.setCode(HttpStatus.HTTP_INTERNAL_ERROR);
        response.setMessage(SysConstant.FAIL_MSG);
        return response;
    }

    /**
     * 失败响应（指定消息）
     *
     * @param message 失败消息
     * @return 响应
     */
    public static Response fail(String message) {
        Response response = new Response();
        response.setCode(HttpStatus.HTTP_INTERNAL_ERROR);
        response.setMessage(message);
        return response;
    }

    /**
     * 未登录响应
     *
     * @return 响应
     */
    public static Response unauthorized() {
        Response response = new Response();
        response.setCode(HttpStatus.HTTP_UNAUTHORIZED);
        response.setMessage(SysConstant.UNAUTHORIZED_MSG);
        return response;
    }

    /**
     * 未授权响应
     *
     * @return 响应
     */
    public static Response forbidden() {
        Response response = new Response();
        response.setCode(HttpStatus.HTTP_FORBIDDEN);
        response.setMessage(SysConstant.FORBIDDEN_MSG);
        return response;
    }

}
